home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_emacs.idb / usr / freeware / info / emacs-20.z / emacs-20 (.txt)
GNU Info File  |  1998-10-27  |  48KB  |  834 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.63 from the
  2. input file emacs.texi.
  3. File: emacs,  Node: Basic Kbd Macro,  Next: Save Kbd Macro,  Up: Keyboard Macros
  4. Basic Use
  5. ---------
  6.    To start defining a keyboard macro, type the `C-x (' command
  7. (`start-kbd-macro').  From then on, your keys continue to be executed,
  8. but also become part of the definition of the macro.  `Def' appears in
  9. the mode line to remind you of what is going on.  When you are
  10. finished, the `C-x )' command (`end-kbd-macro') terminates the
  11. definition (without becoming part of it!).  For example,
  12.      C-x ( M-f foo C-x )
  13. defines a macro to move forward a word and then insert `foo'.
  14.    The macro thus defined can be invoked again with the `C-x e' command
  15. (`call-last-kbd-macro'), which may be given a repeat count as a numeric
  16. argument to execute the macro many times.  `C-x )' can also be given a
  17. repeat count as an argument, in which case it repeats the macro that
  18. many times right after defining it, but defining the macro counts as
  19. the first repetition (since it is executed as you define it).
  20. Therefore, giving `C-x )' an argument of 4 executes the macro
  21. immediately 3 additional times.  An argument of zero to `C-x e' or `C-x
  22. )' means repeat the macro indefinitely (until it gets an error or you
  23. type `C-g').
  24.    If you wish to repeat an operation at regularly spaced places in the
  25. text, define a macro and include as part of the macro the commands to
  26. move to the next place you want to use it.  For example, if you want to
  27. change each line, you should position point at the start of a line, and
  28. define a macro to change that line and leave point at the start of the
  29. next line.  Then repeating the macro will operate on successive lines.
  30.    After you have terminated the definition of a keyboard macro, you
  31. can add to the end of its definition by typing `C-u C-x ('.  This is
  32. equivalent to plain `C-x (' followed by retyping the whole definition
  33. so far.  As a consequence it re-executes the macro as previously
  34. defined.
  35.    You can use function keys in a keyboard macro, just like keyboard
  36. keys.  You can even use mouse events, but be careful about that: when
  37. the macro replays the mouse event, it uses the original mouse position
  38. of that event, the position that the mouse had while you were defining
  39. the macro.  The effect of this may be hard to predict.  (Using the
  40. current mouse position would be even less predictable.)
  41.    One thing that doesn't always work well in a keyboard macro is the
  42. command `C-M-c' (`exit-recursive-edit').  When this command exits a
  43. recursive edit that started within the macro, it works as you'd expect.
  44. But if it exits a recursive edit that started before you invoked the
  45. keyboard macro, it also necessarily exits the keyboard macro as part of
  46. the process.
  47.    You can edit a keyboard macro already defined by typing `C-x C-k'
  48. (`edit-kbd-macro').  Follow that with the keyboard input that you would
  49. use to invoke the macro--`C-x e' or `M-x NAME' or some other key
  50. sequence.  This formats the macro definition in a buffer and enters a
  51. specialized major mode for editing it.  Type `C-h m' once in that
  52. buffer to display details of how to edit the macro.  When you are
  53. finished editing, type `C-c C-c'.
  54.    The command `M-x apply-macro-to-region-lines' repeats the last
  55. defined keyboard macro on each complete line within the current region.
  56. It does this line by line, by moving point to the beginning of the line
  57. and then executing the macro.
  58. File: emacs,  Node: Save Kbd Macro,  Next: Kbd Macro Query,  Prev: Basic Kbd Macro,  Up: Keyboard Macros
  59. Naming and Saving Keyboard Macros
  60. ---------------------------------
  61.    If you wish to save a keyboard macro for longer than until you
  62. define the next one, you must give it a name using `M-x
  63. name-last-kbd-macro'.  This reads a name as an argument using the
  64. minibuffer and defines that name to execute the macro.  The macro name
  65. is a Lisp symbol, and defining it in this way makes it a valid command
  66. name for calling with `M-x' or for binding a key to with
  67. `global-set-key' (*note Keymaps::.).  If you specify a name that has a
  68. prior definition other than another keyboard macro, an error message is
  69. printed and nothing is changed.
  70.    Once a macro has a command name, you can save its definition in a
  71. file.  Then it can be used in another editing session.  First, visit
  72. the file you want to save the definition in.  Then use this command:
  73.      M-x insert-kbd-macro RET MACRONAME RET
  74. This inserts some Lisp code that, when executed later, will define the
  75. same macro with the same definition it has now.  (You need not
  76. understand Lisp code to do this, because `insert-kbd-macro' writes the
  77. Lisp code for you.)  Then save the file.  You can load the file later
  78. with `load-file' (*note Lisp Libraries::.).  If the file you save in is
  79. your init file `~/.emacs' (*note Init File::.) then the macro will be
  80. defined each time you run Emacs.
  81.    If you give `insert-kbd-macro' a numeric argument, it makes
  82. additional Lisp code to record the keys (if any) that you have bound to
  83. the keyboard macro, so that the macro will be reassigned the same keys
  84. when you load the file.
  85. File: emacs,  Node: Kbd Macro Query,  Prev: Save Kbd Macro,  Up: Keyboard Macros
  86. Executing Macros with Variations
  87. --------------------------------
  88.    Using `C-x q' (`kbd-macro-query'), you can get an effect similar to
  89. that of `query-replace', where the macro asks you each time around
  90. whether to make a change.  While defining the macro, type `C-x q' at
  91. the point where you want the query to occur.  During macro definition,
  92. the `C-x q' does nothing, but when you run the macro later, `C-x q'
  93. asks you interactively whether to continue.
  94.    The valid responses when `C-x q' asks are SPC (or `y'), DEL (or
  95. `n'), RET (or `q'), `C-l' and `C-r'.  The answers are the same as in
  96. `query-replace', though not all of the `query-replace' options are
  97. meaningful.
  98.    These responses include SPC to continue, and DEL to skip the
  99. remainder of this repetition of the macro and start right away with the
  100. next repetition.  RET means to skip the remainder of this repetition
  101. and cancel further repetitions.  `C-l' redraws the screen and asks you
  102. again for a character to say what to do.
  103.    `C-r' enters a recursive editing level, in which you can perform
  104. editing which is not part of the macro.  When you exit the recursive
  105. edit using `C-M-c', you are asked again how to continue with the
  106. keyboard macro.  If you type a SPC at this time, the rest of the macro
  107. definition is executed.  It is up to you to leave point and the text in
  108. a state such that the rest of the macro will do what you want.
  109.    `C-u C-x q', which is `C-x q' with a numeric argument, performs a
  110. completely different function.  It enters a recursive edit reading
  111. input from the keyboard, both when you type it during the definition of
  112. the macro, and when it is executed from the macro.  During definition,
  113. the editing you do inside the recursive edit does not become part of
  114. the macro.  During macro execution, the recursive edit gives you a
  115. chance to do some particularized editing on each repetition.  *Note
  116. Recursive Edit::.
  117. File: emacs,  Node: Key Bindings,  Next: Keyboard Translations,  Prev: Keyboard Macros,  Up: Customization
  118. Customizing Key Bindings
  119. ========================
  120.    This section describes "key bindings" which map keys to commands,
  121. and the "keymaps" which record key bindings.  It also explains how to
  122. customize key bindings.
  123.    Recall that a command is a Lisp function whose definition provides
  124. for interactive use.  Like every Lisp function, a command has a function
  125. name which usually consists of lower case letters and hyphens.
  126. * Menu:
  127. * Keymaps::          Generalities.  The global keymap.
  128. * Prefix Keymaps::   Keymaps for prefix keys.
  129. * Local Keymaps::    Major and minor modes have their own keymaps.
  130. * Minibuffer Maps::  The minibuffer uses its own local keymaps.
  131. * Rebinding::        How to redefine one key's meaning conveniently.
  132. * Init Rebinding::   Rebinding keys with your init file, `.emacs'.
  133. * Function Keys::    Rebinding terminal function keys.
  134. * Named ASCII Chars::Distinguishing TAB from `C-i', and so on.
  135. * Mouse Buttons::    Rebinding mouse buttons in Emacs.
  136. * Disabling::        Disabling a command means confirmation is required
  137.                        before it can be executed.  This is done to protect
  138.                        beginners from surprises.
  139. File: emacs,  Node: Keymaps,  Next: Prefix Keymaps,  Up: Key Bindings
  140. Keymaps
  141. -------
  142.    The bindings between key sequences and command functions are recorded
  143. in data structures called "keymaps".  Emacs has many of these, each
  144. used on particular occasions.
  145.    Recall that a "key sequence" ("key", for short) is a sequence of
  146. "input events" that have a meaning as a unit.  Input events include
  147. characters, function keys and mouse buttons--all the inputs that you
  148. can send to the computer with your terminal.  A key sequence gets its
  149. meaning from its "binding", which says what command it runs.  The
  150. function of keymaps is to record these bindings.
  151.    The "global" keymap is the most important keymap because it is
  152. always in effect.  The global keymap defines keys for Fundamental mode;
  153. most of these definitions are common to most or all major modes.  Each
  154. major or minor mode can have its own keymap which overrides the global
  155. definitions of some keys.
  156.    For example, a self-inserting character such as `g' is
  157. self-inserting because the global keymap binds it to the command
  158. `self-insert-command'.  The standard Emacs editing characters such as
  159. `C-a' also get their standard meanings from the global keymap.
  160. Commands to rebind keys, such as `M-x global-set-key', actually work by
  161. storing the new binding in the proper place in the global map.  *Note
  162. Rebinding::.
  163.    Meta characters work differently; Emacs translates each Meta
  164. character into a pair of characters starting with ESC.  When you type
  165. the character `M-a' in a key sequence, Emacs replaces it with `ESC a'.
  166. A meta key comes in as a single input event, but becomes two events for
  167. purposes of key bindings.  The reason for this is historical, and we
  168. might change it someday.
  169.    Most modern keyboards have function keys as well as character keys.
  170. Function keys send input events just as character keys do, and keymaps
  171. can have bindings for them.
  172.    On many terminals, typing a function key actually sends the computer
  173. a sequence of characters; the precise details of the sequence depends on
  174. which function key and on the model of terminal you are using.  (Often
  175. the sequence starts with `ESC ['.)  If Emacs understands your terminal
  176. type properly, it recognizes the character sequences forming function
  177. keys wherever they occur in a key sequence (not just at the beginning).
  178. Thus, for most purposes, you can pretend the function keys reach Emacs
  179. directly and ignore their encoding as character sequences.
  180.    Mouse buttons also produce input events.  These events come with
  181. other data--the window and position where you pressed or released the
  182. button, and a time stamp.  But only the choice of button matters for key
  183. bindings; the other data matters only if a command looks at it.
  184. (Commands designed for mouse invocation usually do look at the other
  185. data.)
  186.    A keymap records definitions for single events.  Interpreting a key
  187. sequence of multiple events involves a chain of keymaps.  The first
  188. keymap gives a definition for the first event; this definition is
  189. another keymap, which is used to look up the second event in the
  190. sequence, and so on.
  191.    Key sequences can mix function keys and characters.  For example,
  192. `C-x SELECT' makes sense.  If you make SELECT a prefix key, then
  193. `SELECT C-n' makes sense.  You can even mix mouse events with keyboard
  194. events, but we recommend against it, because such sequences are
  195. inconvenient to type in.
  196.    As a user, you can redefine any key; but it might be best to stick to
  197. key sequences that consist of `C-c' followed by a letter.  These keys
  198. are "reserved for users,", so they won't conflict with any properly
  199. designed Emacs extension.  If you redefine some other key, your
  200. definition may be overridden by certain extensions or major modes which
  201. redefine the same key.
  202. File: emacs,  Node: Prefix Keymaps,  Next: Local Keymaps,  Prev: Keymaps,  Up: Key Bindings
  203. Prefix Keymaps
  204. --------------
  205.    A prefix key such as `C-x' or ESC has its own keymap, which holds
  206. the definition for the event that immediately follows that prefix.
  207.    The definition of a prefix key is usually the keymap to use for
  208. looking up the following event.  The definition can also be a Lisp
  209. symbol whose function definition is the following keymap; the effect is
  210. the same, but it provides a command name for the prefix key that can be
  211. used as a description of what the prefix key is for.  Thus, the binding
  212. of `C-x' is the symbol `Ctl-X-Prefix', whose function definition is the
  213. keymap for `C-x' commands.  The definitions of `C-c', `C-x', `C-h' and
  214. ESC as prefix keys appear in the global map, so these prefix keys are
  215. always available.
  216.    Aside from ordinary prefix keys, there is a fictitious "prefix key"
  217. which represents the menu bar; see *Note Menu Bar: (elisp)Menu Bar, for
  218. special information about menu bar key bindings.  Mouse button events
  219. that invoke pop-up menus are also prefix keys; see *Note Menu Keymaps:
  220. (elisp)Menu Keymaps, for more details.
  221.    Some prefix keymaps are stored in variables with names:
  222.    * `ctl-x-map' is the variable name for the map used for characters
  223.      that follow `C-x'.
  224.    * `help-map' is for characters that follow `C-h'.
  225.    * `esc-map' is for characters that follow ESC.  Thus, all Meta
  226.      characters are actually defined by this map.
  227.    * `ctl-x-4-map' is for characters that follow `C-x 4'.
  228.    * `mode-specific-map' is for characters that follow `C-c'.
  229. File: emacs,  Node: Local Keymaps,  Next: Minibuffer Maps,  Prev: Prefix Keymaps,  Up: Key Bindings
  230. Local Keymaps
  231. -------------
  232.    So far we have explained the ins and outs of the global map.  Major
  233. modes customize Emacs by providing their own key bindings in "local
  234. keymaps".  For example, C mode overrides TAB to make it indent the
  235. current line for C code.  Portions of text in the buffer can specify
  236. their own keymaps to substitute for the keymap of the buffer's major
  237. mode.
  238.    Minor modes can also have local keymaps.  Whenever a minor mode is
  239. in effect, the definitions in its keymap override both the major mode's
  240. local keymap and the global keymap.
  241.    The local keymaps for Lisp mode and several other major modes always
  242. exist even when not in use.  These are kept in variables named
  243. `lisp-mode-map' and so on.  For major modes less often used, the local
  244. keymap is normally constructed only when the mode is used for the first
  245. time in a session.  This is to save space.  If you wish to change one
  246. of these keymaps, you must use the major mode's "mode hook"--see below.
  247.    All minor mode keymaps are created in advance.  There is no way to
  248. defer their creation until the first time the minor mode is enabled.
  249.    A local keymap can locally redefine a key as a prefix key by defining
  250. it as a prefix keymap.  If the key is also defined globally as a prefix,
  251. then its local and global definitions (both keymaps) effectively
  252. combine: both of them are used to look up the event that follows the
  253. prefix key.  Thus, if the mode's local keymap defines `C-c' as another
  254. keymap, and that keymap defines `C-z' as a command, this provides a
  255. local meaning for `C-c C-z'.  This does not affect other sequences that
  256. start with `C-c'; if those sequences don't have their own local
  257. bindings, their global bindings remain in effect.
  258.    Another way to think of this is that Emacs handles a multi-event key
  259. sequence by looking in several keymaps, one by one, for a binding of the
  260. whole key sequence.  First it checks the minor mode keymaps for minor
  261. modes that are enabled, then it checks the major mode's keymap, and then
  262. it checks the global keymap.  This is not precisely how key lookup
  263. works, but it's good enough for understanding ordinary circumstances.
  264.    To change the local bindings of a major mode, you must change the
  265. mode's local keymap.  Normally you must wait until the first time the
  266. mode is used, because most major modes don't create their keymaps until
  267. then.  If you want to specify something in your `~/.emacs' file to
  268. change a major mode's bindings, you must use the mode's mode hook to
  269. delay the change until the mode is first used.
  270.    For example, the command `texinfo-mode' to select Texinfo mode runs
  271. the hook `texinfo-mode-hook'.  Here's how you can use the hook to add
  272. local bindings (not very useful, we admit) for `C-c n' and `C-c p' in
  273. Texinfo mode:
  274.      (add-hook 'texinfo-mode-hook
  275.                '(lambda ()
  276.                   (define-key texinfo-mode-map
  277.                               "\C-cp"
  278.                               'backward-paragraph)
  279.                   (define-key texinfo-mode-map
  280.                               "\C-cn"
  281.                               'forward-paragraph)
  282.                   ))
  283.    *Note Hooks::.
  284. File: emacs,  Node: Minibuffer Maps,  Next: Rebinding,  Prev: Local Keymaps,  Up: Key Bindings
  285. Minibuffer Keymaps
  286. ------------------
  287.    The minibuffer has its own set of local keymaps; they contain various
  288. completion and exit commands.
  289.    * `minibuffer-local-map' is used for ordinary input (no completion).
  290.    * `minibuffer-local-ns-map' is similar, except that SPC exits just
  291.      like RET.  This is used mainly for Mocklisp compatibility.
  292.    * `minibuffer-local-completion-map' is for permissive completion.
  293.    * `minibuffer-local-must-match-map' is for strict completion and for
  294.      cautious completion.
  295. File: emacs,  Node: Rebinding,  Next: Init Rebinding,  Prev: Minibuffer Maps,  Up: Key Bindings
  296. Changing Key Bindings Interactively
  297. -----------------------------------
  298.    The way to redefine an Emacs key is to change its entry in a keymap.
  299. You can change the global keymap, in which case the change is effective
  300. in all major modes (except those that have their own overriding local
  301. definitions for the same key).  Or you can change the current buffer's
  302. local map, which affects all buffers using the same major mode.
  303. `M-x global-set-key RET KEY CMD RET'
  304.      Define KEY globally to run CMD.
  305. `M-x local-set-key RET KEY CMD RET'
  306.      Define KEY locally (in the major mode now in effect) to run CMD.
  307. `M-x global-unset-key RET KEY'
  308.      Make KEY undefined in the global map.
  309. `M-x local-unset-key RET KEY'
  310.      Make KEY undefined locally (in the major mode now in effect).
  311.    For example, suppose you like to execute commands in a subshell
  312. within an Emacs buffer, instead of suspending Emacs and executing
  313. commands in your login shell.  Normally, `C-z' is bound to the function
  314. `suspend-emacs' (when not using the X Window System), but you can
  315. change `C-z' to invoke an interactive subshell within Emacs, by binding
  316. it to `shell' as follows:
  317.      M-x global-set-key RET C-z shell RET
  318. `global-set-key' reads the command name after the key.   After you
  319. press the key, a message like this appears so that you can confirm that
  320. you are binding the key you want:
  321.      Set key C-z to command:
  322.    You can redefine function keys and mouse events in the same way; just
  323. type the function key or click the mouse when it's time to specify the
  324. key to rebind.
  325.    You can rebind a key that contains more than one event in the same
  326. way.  Emacs keeps reading the key to rebind until it is a complete key
  327. (that is, not a prefix key).  Thus, if you type `C-f' for KEY, that's
  328. the end; the minibuffer is entered immediately to read CMD.  But if you
  329. type `C-x', another character is read; if that is `4', another
  330. character is read, and so on.  For example,
  331.      M-x global-set-key RET C-x 4 $ spell-other-window RET
  332. redefines `C-x 4 $' to run the (fictitious) command
  333. `spell-other-window'.
  334.    The two-character keys consisting of `C-c' followed by a letter are
  335. reserved for user customizations.  Lisp programs are not supposed to
  336. define these keys, so the bindings you make for them will be available
  337. in all major modes and will never get in the way of anything.
  338.    You can remove the global definition of a key with
  339. `global-unset-key'.  This makes the key "undefined"; if you type it,
  340. Emacs will just beep.  Similarly, `local-unset-key' makes a key
  341. undefined in the current major mode keymap, which makes the global
  342. definition (or lack of one) come back into effect in that major mode.
  343.    If you have redefined (or undefined) a key and you subsequently wish
  344. to retract the change, undefining the key will not do the job--you need
  345. to redefine the key with its standard definition.  To find the name of
  346. the standard definition of a key, go to a Fundamental mode buffer and
  347. use `C-h c'.  The documentation of keys in this manual also lists their
  348. command names.
  349.    If you want to prevent yourself from invoking a command by mistake,
  350. it is better to disable the command than to undefine the key.  A
  351. disabled command is less work to invoke when you really want to.  *Note
  352. Disabling::.
  353. File: emacs,  Node: Init Rebinding,  Next: Function Keys,  Prev: Rebinding,  Up: Key Bindings
  354. Rebinding Keys in Your Init File
  355. --------------------------------
  356.    If you have a set of key bindings that you like to use all the time,
  357. you can specify them in your `.emacs' file by using their Lisp syntax.
  358.    The simplest method for doing this works for ASCII characters and
  359. Meta-modified ASCII characters only.  This method uses a string to
  360. represent the key sequence you want to rebind.  For example, here's how
  361. to bind `C-z' to `shell':
  362.      (global-set-key "\C-z" 'shell)
  363. This example uses a string constant containing one character, `C-z'.
  364. The single-quote before the command name, `shell', marks it as a
  365. constant symbol rather than a variable.  If you omit the quote, Emacs
  366. would try to evaluate `shell' immediately as a variable.  This probably
  367. causes an error; it certainly isn't what you want.
  368.    Here is another example that binds a key sequence two characters
  369. long:
  370.      (global-set-key "\C-xl" 'make-symbolic-link)
  371.    When the key sequence includes function keys or mouse button events,
  372. or non-ASCII characters such as `C-=' or `H-a', you must use the more
  373. general method of rebinding, which uses a vector to specify the key
  374. sequence.
  375.    The way to write a vector in Emacs Lisp is with square brackets
  376. around the vector elements.  Use spaces to separate the elements.  If an
  377. element is a symbol, simply write the symbol's name--no other
  378. delimiters or punctuation are needed.  If a vector element is a
  379. character, write it as a Lisp character constant: `?' followed by the
  380. character as it would appear in a string.
  381.    Here are examples of using vectors to rebind `C-=' (a control
  382. character outside of ASCII), `H-a' (a Hyper character; ASCII doesn't
  383. have Hyper at all); f7 (a function key), and `C-Mouse-1' (a
  384. keyboard-modified mouse button):
  385.      (global-set-key [?\C-=] 'make-symbolic-link)
  386.      (global-set-key [?\H-a] 'make-symbolic-link)
  387.      (global-set-key [f7] 'make-symbolic-link)
  388.      (global-set-key [C-mouse-1] 'make-symbolic-link)
  389.    You can use a vector for the simple cases too.  Here's how to rewrite
  390. the first two examples, above, to use vectors:
  391.      (global-set-key [?\C-z] 'shell)
  392.      
  393.      (global-set-key [?\C-x ?l] 'make-symbolic-link)
  394. File: emacs,  Node: Function Keys,  Next: Named ASCII Chars,  Prev: Init Rebinding,  Up: Key Bindings
  395. Rebinding Function Keys
  396. -----------------------
  397.    Key sequences can contain function keys as well as ordinary
  398. characters.  Just as Lisp characters (actually integers) represent
  399. keyboard characters, Lisp symbols represent function keys.  If the
  400. function key has a word as its label, then that word is also the name of
  401. the corresponding Lisp symbol.  Here are the conventional Lisp names for
  402. common function keys:
  403. `left', `up', `right', `down'
  404.      Cursor arrow keys.
  405. `begin', `end', `home', `next', `prior'
  406.      Other cursor repositioning keys.
  407. `select', `print', `execute', `backtab'
  408. `insert', `undo', `redo', `clearline'
  409. `insertline', `deleteline', `insertchar', `deletechar',
  410.      Miscellaneous function keys.
  411. `f1', `f2', ... `f35'
  412.      Numbered function keys (across the top of the keyboard).
  413. `kp-add', `kp-subtract', `kp-multiply', `kp-divide'
  414. `kp-backtab', `kp-space', `kp-tab', `kp-enter'
  415. `kp-separator', `kp-decimal', `kp-equal'
  416.      Keypad keys (to the right of the regular keyboard), with names or
  417.      punctuation.
  418. `kp-0', `kp-1', ... `kp-9'
  419.      Keypad keys with digits.
  420. `kp-f1', `kp-f2', `kp-f3', `kp-f4'
  421.      Keypad PF keys.
  422.    These names are conventional, but some systems (especially when using
  423. X windows) may use different names.  To make certain what symbol is used
  424. for a given function key on your terminal, type `C-h c' followed by
  425. that key.
  426.    A key sequence which contains function key symbols (or anything but
  427. ASCII characters) must be a vector rather than a string.  The vector
  428. syntax uses spaces between the elements, and square brackets around the
  429. whole vector.  Thus, to bind function key `f1' to the command `rmail',
  430. write the following:
  431.      (global-set-key [f1] 'rmail)
  432. To bind the right-arrow key to the command `forward-char', you can use
  433. this expression:
  434.      (global-set-key [right] 'forward-char)
  435. This uses the Lisp syntax for a vector containing the symbol `right'.
  436. (This binding is present in Emacs by default.)
  437.    *Note Init Rebinding::, for more information about using vectors for
  438. rebinding.
  439.    You can mix function keys and characters in a key sequence.  This
  440. example binds `C-x NEXT' to the command `forward-page'.
  441.      (global-set-key [?\C-x next] 'forward-page)
  442. where `?\C-x' is the Lisp character constant for the character `C-x'.
  443. The vector element `next' is a symbol and therefore does not take a
  444. question mark.
  445.    You can use the modifier keys CTRL, META, HYPER, SUPER, ALT and
  446. SHIFT with function keys.  To represent these modifiers, add the
  447. strings `C-', `M-', `H-', `s-', `A-' and `S-' at the front of the
  448. symbol name.  Thus, here is how to make `Hyper-Meta-RIGHT' move forward
  449. a word:
  450.      (global-set-key [H-M-right] 'forward-word)
  451. File: emacs,  Node: Named ASCII Chars,  Next: Mouse Buttons,  Prev: Function Keys,  Up: Key Bindings
  452. Named ASCII Control Characters
  453. ------------------------------
  454.    TAB, RET, BS, LFD, ESC and DEL started out as names for certain
  455. ASCII control characters, used so often that they have special keys of
  456. their own.  Later, users found it convenient to distinguish in Emacs
  457. between these keys and the "same" control characters typed with the
  458. CTRL key.
  459.    Emacs 19 distinguishes these two kinds of input, when used with the X
  460. Window System.  It treats the "special" keys as function keys named
  461. `tab', `return', `backspace', `linefeed', `escape', and `delete'.
  462. These function keys translate automatically into the corresponding
  463. ASCII characters *if* they have no bindings of their own.  As a result,
  464. neither users nor Lisp programs need to pay attention to the
  465. distinction unless they care to.
  466.    If you do not want to distinguish between (for example) TAB and
  467. `C-i', make just one binding, for the ASCII character TAB (octal code
  468. 011).  If you do want to distinguish, make one binding for this ASCII
  469. character, and another for the "function key" `tab'.
  470.    With an ordinary ASCII terminal, there is no way to distinguish
  471. between TAB and `C-i' (and likewise for other such pairs), because the
  472. terminal sends the same character in both cases.
  473. File: emacs,  Node: Mouse Buttons,  Next: Disabling,  Prev: Named ASCII Chars,  Up: Key Bindings
  474. Rebinding Mouse Buttons
  475. -----------------------
  476.    Emacs uses Lisp symbols to designate mouse buttons, too.  The
  477. ordinary mouse events in Emacs are "click" events; these happen when you
  478. press a button and release it without moving the mouse.  You can also
  479. get "drag" events, when you move the mouse while holding the button
  480. down.  Drag events happen when you finally let go of the button.
  481.    The symbols for basic click events are `mouse-1' for the leftmost
  482. button, `mouse-2' for the next, and so on.  Here is how you can
  483. redefine the second mouse button to split the current window:
  484.      (global-set-key [mouse-2] 'split-window-vertically)
  485.    The symbols for drag events are similar, but have the prefix `drag-'
  486. before the word `mouse'.  For example, dragging the first button
  487. generates a `drag-mouse-1' event.
  488.    You can also define bindings for events that occur when a mouse
  489. button is pressed down.  These events start with `down-' instead of
  490. `drag-'.  Such events are generated only if they have key bindings.
  491. When you get a button-down event, a corresponding click or drag event
  492. will always follow.
  493.    If you wish, you can distinguish single, double, and triple clicks.
  494. A double click means clicking a mouse button twice in approximately the
  495. same place.  The first click generates an ordinary click event.  The
  496. second click, if it comes soon enough, generates a double-click event
  497. instead.  The event type for a double click event starts with
  498. `double-': for example, `double-mouse-3'.
  499.    This means that you can give a special meaning to the second click at
  500. the same place, but it must act on the assumption that the ordinary
  501. single click definition has run when the first click was received.
  502.    This constrains what you can do with double clicks, but user
  503. interface designers say that this constraint ought to be followed in
  504. any case.  A double click should do something similar to the single
  505. click, only "more so".  The command for the double-click event should
  506. perform the extra work for the double click.
  507.    If a double-click event has no binding, it changes to the
  508. corresponding single-click event.  Thus, if you don't define a
  509. particular double click specially, it executes the single-click command
  510. twice.
  511.    Emacs also supports triple-click events whose names start with
  512. `triple-'.  Emacs does not distinguish quadruple clicks as event types;
  513. clicks beyond the third generate additional triple-click events.
  514. However, the full number of clicks is recorded in the event list, so you
  515. can distinguish if you really want to.  We don't recommend distinct
  516. meanings for more than three clicks, but sometimes it is useful for
  517. subsequent clicks to cycle through the same set of three meanings, so
  518. that four clicks are equivalent to one click, five are equivalent to
  519. two, and six are equivalent to three.
  520.    Emacs also records multiple presses in drag and button-down events.
  521. For example, when you press a button twice, then move the mouse while
  522. holding the button, Emacs gets a `double-drag-' event.  And at the
  523. moment when you press it down for the second time, Emacs gets a
  524. `double-down-' event (which is ignored, like all button-down events, if
  525. it has no binding).
  526.    The variable `double-click-time' specifies how long may elapse
  527. between clicks that are recognized as a pair.  Its value is measured in
  528. milliseconds.  If the value is `nil', double clicks are not detected at
  529. all.  If the value is `t', then there is no time limit.
  530.    The symbols for mouse events also indicate the status of the modifier
  531. keys, with the usual prefixes `C-', `M-', `H-', `s-', `A-' and `S-'.
  532. These always precede `double-' or `triple-', which always precede
  533. `drag-' or `down-'.
  534.    A frame includes areas that don't show text from the buffer, such as
  535. the mode line and the scroll bar.  You can tell whether a mouse button
  536. comes from a special area of the screen by means of dummy "prefix
  537. keys."  For example, if you click the mouse in the mode line, you get
  538. the prefix key `mode-line' before the ordinary mouse-button symbol.
  539. Thus, here is how to define the command for clicking the first button in
  540. a mode line to run `scroll-up':
  541.      (global-set-key [mode-line mouse-1] 'scroll-up)
  542.    Here is the complete list of these dummy prefix keys and their
  543. meanings:
  544. `mode-line'
  545.      The mouse was in the mode line of a window.
  546. `vertical-line'
  547.      The mouse was in the vertical line separating side-by-side
  548.      windows.  (If you use scroll bars, they appear in place of these
  549.      vertical lines.)
  550. `vertical-scroll-bar'
  551.      The mouse was in a vertical scroll bar.  (This is the only kind of
  552.      scroll bar Emacs currently supports.)
  553.    You can put more than one mouse button in a key sequence, but it
  554. isn't usual to do so.
  555. File: emacs,  Node: Disabling,  Prev: Mouse Buttons,  Up: Key Bindings
  556. Disabling Commands
  557. ------------------
  558.    Disabling a command marks the command as requiring confirmation
  559. before it can be executed.  The purpose of disabling a command is to
  560. prevent beginning users from executing it by accident and being
  561. confused.
  562.    An attempt to invoke a disabled command interactively in Emacs
  563. displays a window containing the command's name, its documentation, and
  564. some instructions on what to do immediately; then Emacs asks for input
  565. saying whether to execute the command as requested, enable it and
  566. execute it, or cancel.  If you decide to enable the command, you are
  567. asked whether to do this permanently or just for the current session.
  568. Enabling permanently works by automatically editing your `.emacs' file.
  569.    The direct mechanism for disabling a command is to put a non-`nil'
  570. `disabled' property on the Lisp symbol for the command.  Here is the
  571. Lisp program to do this:
  572.      (put 'delete-region 'disabled t)
  573.    If the value of the `disabled' property is a string, that string is
  574. included in the message printed when the command is used:
  575.      (put 'delete-region 'disabled
  576.           "It's better to use `kill-region' instead.\n")
  577.    You can make a command disabled either by editing the `.emacs' file
  578. directly or with the command `M-x disable-command', which edits the
  579. `.emacs' file for you.  Likewise, `M-x enable-command' edits `.emacs'
  580. to enable a command permanently.  *Note Init File::.
  581.    Whether a command is disabled is independent of what key is used to
  582. invoke it; disabling also applies if the command is invoked using
  583. `M-x'.  Disabling a command has no effect on calling it as a function
  584. from Lisp programs.
  585. File: emacs,  Node: Keyboard Translations,  Next: Syntax,  Prev: Key Bindings,  Up: Customization
  586. Keyboard Translations
  587. =====================
  588.    Some keyboards do not make it convenient to send all the special
  589. characters that Emacs uses.  The most common problem case is the DEL
  590. character.  Some keyboards provide no convenient way to type this very
  591. important character--usually because they were designed to expect the
  592. character `C-h' to be used for deletion.  On these keyboard, if you
  593. press the key normally used for deletion, Emacs handles the `C-h' as a
  594. prefix character and offers you a list of help options, which is not
  595. what you want.
  596.    You can work around this problem within Emacs by setting up keyboard
  597. translations to turn `C-h' into DEL and DEL into `C-h', as follows:
  598.      ;; Translate `C-h' to DEL.
  599.      (keyboard-translate ?\C-h ?\C-?)
  600.      
  601.      ;; Translate DEL to `C-h'.
  602.      (keyboard-translate ?\C-? ?\C-h)
  603.    Keyboard translations are not the same as key bindings in keymaps
  604. (*note Keymaps::.).  Emacs contains numerous keymaps that apply in
  605. different situations, but there is only one set of keyboard
  606. translations, and it applies to every character that Emacs reads from
  607. the terminal.  Keyboard translations take place at the lowest level of
  608. input processing; the keys that are looked up in keymaps contain the
  609. characters that result from keyboard translation.
  610.    Under X, the keyboard key named DELETE is a function key and is
  611. distinct from the ASCII character named DEL.  *Note Named ASCII
  612. Chars::.  Keyboard translations affect only ASCII character input, not
  613. function keys; thus, the above example used under X does not affect the
  614. DELETE key.  However, the translation above isn't necessary under X,
  615. because Emacs can also distinguish between the BACKSPACE key and `C-h';
  616. and it normally treats BACKSPACE as DEL.
  617.    For full information about how to use keyboard translations, see
  618. *Note Translating Input: (elisp)Translating Input.
  619. File: emacs,  Node: Syntax,  Next: Init File,  Prev: Keyboard Translations,  Up: Customization
  620. The Syntax Table
  621. ================
  622.    All the Emacs commands which parse words or balance parentheses are
  623. controlled by the "syntax table".  The syntax table says which
  624. characters are opening delimiters, which are parts of words, which are
  625. string quotes, and so on.  Each major mode has its own syntax table
  626. (though sometimes related major modes use the same one) which it
  627. installs in each buffer that uses that major mode.  The syntax table
  628. installed in the current buffer is the one that all commands use, so we
  629. call it "the" syntax table.  A syntax table is a Lisp object, a vector
  630. of length 256 whose elements are numbers.
  631.    To display a description of the contents of the current syntax table,
  632. type `C-h s' (`describe-syntax').  The description of each character
  633. includes both the string you would have to give to
  634. `modify-syntax-entry' to set up that character's current syntax, and
  635. some English to explain that string if necessary.
  636.    For full information on the syntax table, see *Note Syntax Tables:
  637. (elisp)Syntax Tables.
  638. File: emacs,  Node: Init File,  Prev: Syntax,  Up: Customization
  639. The Init File, `~/.emacs'
  640. =========================
  641.    When Emacs is started, it normally loads a Lisp program from the file
  642. `.emacs' in your home directory.  We call this file your "init file"
  643. because it specifies how to initialize Emacs for you.  You can use the
  644. command line switches `-q' and `-u' to tell Emacs whether to load an
  645. init file, and which one (*note Entering Emacs::.).
  646.    There can also be a "default init file", which is the library named
  647. `default.el', found via the standard search path for libraries.  The
  648. Emacs distribution contains no such library; your site may create one
  649. for local customizations.  If this library exists, it is loaded
  650. whenever you start Emacs (except when you specify `-q').  But your init
  651. file, if any, is loaded first; if it sets `inhibit-default-init'
  652. non-`nil', then `default' is not loaded.
  653.    Your site may also have a "site startup file"; this is named
  654. `site-start.el', if it exists.  Emacs loads this library before it
  655. loads your init file.  To inhibit loading of this library, use the
  656. option `-no-site-file'.
  657.    If you have a large amount of code in your `.emacs' file, you should
  658. move it into another file such as `~/SOMETHING.el', byte-compile it,
  659. and make your `.emacs' file load it with `(load "~/SOMETHING")'.  *Note
  660. Byte Compilation: (elisp)Byte Compilation, for more information about
  661. compiling Emacs Lisp programs.
  662. * Menu:
  663. * Init Syntax::         Syntax of constants in Emacs Lisp.
  664. * Init Examples::    How to do some things with an init file.
  665. * Terminal Init::    Each terminal type can have an init file.
  666. * Find Init::         How Emacs finds the init file.
  667. File: emacs,  Node: Init Syntax,  Next: Init Examples,  Up: Init File
  668. Init File Syntax
  669. ----------------
  670.    The `.emacs' file contains one or more Lisp function call
  671. expressions.  Each of these consists of a function name followed by
  672. arguments, all surrounded by parentheses.  For example, `(setq
  673. fill-column 60)' calls the function `setq' to set the variable
  674. `fill-column' (*note Filling::.) to 60.
  675.    The second argument to `setq' is an expression for the new value of
  676. the variable.  This can be a constant, a variable, or a function call
  677. expression.  In `.emacs', constants are used most of the time.  They
  678. can be:
  679. Numbers:
  680.      Numbers are written in decimal, with an optional initial minus
  681.      sign.
  682. Strings:
  683.      Lisp string syntax is the same as C string syntax with a few extra
  684.      features.  Use a double-quote character to begin and end a string
  685.      constant.
  686.      In a string, you can include newlines and special characters
  687.      literally.  But often it is cleaner to use backslash sequences for
  688.      them: `\n' for newline, `\b' for backspace, `\r' for carriage
  689.      return, `\t' for tab, `\f' for formfeed (control-L), `\e' for
  690.      escape, `\\' for a backslash, `\"' for a double-quote, or `\OOO'
  691.      for the character whose octal code is OOO.  Backslash and
  692.      double-quote are the only characters for which backslash sequences
  693.      are mandatory.
  694.      `\C-' can be used as a prefix for a control character, as in
  695.      `\C-s' for ASCII control-S, and `\M-' can be used as a prefix for
  696.      a Meta character, as in `\M-a' for `Meta-A' or `\M-\C-a' for
  697.      `Control-Meta-A'.
  698. Characters:
  699.      Lisp character constant syntax consists of a `?' followed by
  700.      either a character or an escape sequence starting with `\'.
  701.      Examples: `?x', `?\n', `?\"', `?\)'.  Note that strings and
  702.      characters are not interchangeable in Lisp; some contexts require
  703.      one and some contexts require the other.
  704. True:
  705.      `t' stands for `true'.
  706. False:
  707.      `nil' stands for `false'.
  708. Other Lisp objects:
  709.      Write a single-quote (') followed by the Lisp object you want.
  710. File: emacs,  Node: Init Examples,  Next: Terminal Init,  Prev: Init Syntax,  Up: Init File
  711. Init File Examples
  712. ------------------
  713.    Here are some examples of doing certain commonly desired things with
  714. Lisp expressions:
  715.    * Make TAB in C mode just insert a tab if point is in the middle of a
  716.      line.
  717.           (setq c-tab-always-indent nil)
  718.      Here we have a variable whose value is normally `t' for `true' and
  719.      the alternative is `nil' for `false'.
  720.    * Make searches case sensitive by default (in all buffers that do not
  721.      override this).
  722.           (setq-default case-fold-search nil)
  723.      This sets the default value, which is effective in all buffers
  724.      that do not have local values for the variable.  Setting
  725.      `case-fold-search' with `setq' affects only the current buffer's
  726.      local value, which is not what you probably want to do in an init
  727.      file.
  728.    * Specify your own email address, if Emacs can't figure it out
  729.      correctly.
  730.           (setq user-mail-address "coon@yoyodyne.com")
  731.      Various Emacs packages that need your own email address use the
  732.      value of `user-mail-address'.
  733.    * Make Text mode the default mode for new buffers.
  734.           (setq default-major-mode 'text-mode)
  735.      Note that `text-mode' is used because it is the command for
  736.      entering Text mode.  The single-quote before it makes the symbol a
  737.      constant; otherwise, `text-mode' would be treated as a variable
  738.      name.
  739.    * Turn on Auto Fill mode automatically in Text mode and related
  740.      modes.
  741.           (add-hook 'text-mode-hook
  742.             '(lambda () (auto-fill-mode 1)))
  743.      This shows how to add a hook function to a normal hook variable
  744.      (*note Hooks::.).  The function we supply is a list starting with
  745.      `lambda', with a single-quote in front of it to make it a list
  746.      constant rather than an expression.
  747.      It's beyond the scope of this manual to explain Lisp functions,
  748.      but for this example it is enough to know that the effect is to
  749.      execute `(auto-fill-mode 1)' when Text mode is entered.  You can
  750.      replace that with any other expression that you like, or with
  751.      several expressions in a row.
  752.      Emacs comes with a function named `turn-on-auto-fill' whose
  753.      definition is `(lambda () (auto-fill-mode 1))'.  Thus, a simpler
  754.      way to write the above example is as follows:
  755.           (add-hook 'text-mode-hook 'turn-on-auto-fill)
  756.    * Load the installed Lisp library named `foo' (actually a file
  757.      `foo.elc' or `foo.el' in a standard Emacs directory).
  758.           (load "foo")
  759.      When the argument to `load' is a relative file name, not starting
  760.      with `/' or `~', `load' searches the directories in `load-path'
  761.      (*note Lisp Libraries::.).
  762.    * Load the compiled Lisp file `foo.elc' from your home directory.
  763.           (load "~/foo.elc")
  764.      Here an absolute file name is used, so no searching is done.
  765.    * Rebind the key `C-x l' to run the function `make-symbolic-link'.
  766.           (global-set-key "\C-xl" 'make-symbolic-link)
  767.      or
  768.           (define-key global-map "\C-xl" 'make-symbolic-link)
  769.      Note once again the single-quote used to refer to the symbol
  770.      `make-symbolic-link' instead of its value as a variable.
  771.    * Do the same thing for Lisp mode only.
  772.           (define-key lisp-mode-map "\C-xl" 'make-symbolic-link)
  773.    * Redefine all keys which now run `next-line' in Fundamental mode so
  774.      that they run `forward-line' instead.
  775.           (substitute-key-definition 'next-line 'forward-line
  776.                                      global-map)
  777.    * Make `C-x C-v' undefined.
  778.           (global-unset-key "\C-x\C-v")
  779.      One reason to undefine a key is so that you can make it a prefix.
  780.      Simply defining `C-x C-v ANYTHING' will make `C-x C-v' a prefix,
  781.      but `C-x C-v' must first be freed of its usual non-prefix
  782.      definition.
  783.    * Make `$' have the syntax of punctuation in Text mode.  Note the
  784.      use of a character constant for `$'.
  785.           (modify-syntax-entry ?\$ "." text-mode-syntax-table)
  786.    * Enable the use of the command `eval-expression' without
  787.      confirmation.
  788.           (put 'eval-expression 'disabled nil)
  789. File: emacs,  Node: Terminal Init,  Next: Find Init,  Prev: Init Examples,  Up: Init File
  790. Terminal-specific Initialization
  791. --------------------------------
  792.    Each terminal type can have a Lisp library to be loaded into Emacs
  793. when it is run on that type of terminal.  For a terminal type named
  794. TERMTYPE, the library is called `term/TERMTYPE' and it is found by
  795. searching the directories `load-path' as usual and trying the suffixes
  796. `.elc' and `.el'.  Normally it appears in the subdirectory `term' of
  797. the directory where most Emacs libraries are kept.
  798.    The usual purpose of the terminal-specific library is to map the
  799. escape sequences used by the terminal's function keys onto more
  800. meaningful names, using `function-key-map'.  See the file
  801. `term/lk201.el' for an example of how this is done.  Many function keys
  802. are mapped automatically according to the information in the Termcap
  803. data base; the terminal-specific library needs to map only the function
  804. keys that Termcap does not specify.
  805.    When the terminal type contains a hyphen, only the part of the name
  806. before the first hyphen is significant in choosing the library name.
  807. Thus, terminal types `aaa-48' and `aaa-30-rv' both use the library
  808. `term/aaa'.  The code in the library can use `(getenv "TERM")' to find
  809. the full terminal type name.
  810.    The library's name is constructed by concatenating the value of the
  811. variable `term-file-prefix' and the terminal type.  Your `.emacs' file
  812. can prevent the loading of the terminal-specific library by setting
  813. `term-file-prefix' to `nil'.
  814.    Emacs runs the hook `term-setup-hook' at the end of initialization,
  815. after both your `.emacs' file and any terminal-specific library have
  816. been read in.  Add hook functions to this hook if you wish to override
  817. part of any of the terminal-specific libraries and to define
  818. initializations for terminals that do not have a library.  *Note
  819. Hooks::.
  820. File: emacs,  Node: Find Init,  Prev: Terminal Init,  Up: Init File
  821. How Emacs Finds Your Init File
  822. ------------------------------
  823.    Normally Emacs uses the environment variable `HOME' to find
  824. `.emacs'; that's what `~' means in a file name.  But if you have done
  825. `su', Emacs tries to find your own `.emacs', not that of the user you
  826. are currently pretending to be.  The idea is that you should get your
  827. own editor customizations even if you are running as the super user.
  828.    More precisely, Emacs first determines which user's init file to use.
  829. It gets the user name from the environment variables `LOGNAME' and
  830. `USER'; if neither of those exists, it uses effective user-ID.  If that
  831. user name matches the real user-ID, then Emacs uses `HOME'; otherwise,
  832. it looks up the home directory corresponding to that user name in the
  833. system's data base of users.
  834.